package com.love.labuladong.twopoint.slidewindow;

/**
 * @Author : zh
 * @Description : 209 长度最小的子数组
 * @Date : 2024-08-30 15:18
 */
public class LengthMinSubArray {


    public int minSubArrayLen(int target, int[] nums) {
        int l = 0;
        int r = 0;
        int sum = 0;
        int ans = Integer.MAX_VALUE;
        int n = nums.length;
        while(r < n){
            sum += nums[r];
            while(sum >= target){
                ans = Math.min(ans,r -l + 1);
                sum -= nums[l];
                l++;
            }
            r++;
        }
        return ans ==  Integer.MAX_VALUE ? 0 : ans;
    }

}
